<?php
/*
 * Source from : http://www.php.net/manual/en/book.pdo.php#93178
 */
include "DBConfig.class.php";

class DBConnect {
	private static $objInstance; 
	
	
	
	/* 
     * Class Constructor - Create a new database connection if one doesn't exist 
     * Set to private so no-one can create a new instance via ' = new DB();' 
     */
	public function __construct()
	{
		//parent::__construct($databaseHostname, $databaseUsername, $databasePassword, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
	}
	
	/* 
     * Like the constructor, we make __clone private so nobody can clone the instance 
     */
	private function __clone() {}
	

	
	/* 
     * Returns DB instance or create initial connection 
     * @param 
     * @return $objInstance; 
     */ 
    public static function getInstance(  ) { 
            
      if(!self::$objInstance){ 
      	
      	try {
           self::$objInstance = new PDO(DBConfig::$databaseType.":host".DBConfig::$databaseHostname.";dbname=".DBConfig::$databaseName, DBConfig::$databaseUsername, DBConfig::$databasePassword); 
           self::$objInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
       	}catch (PDOException $e){
       	
       	}
      } 
        
      return self::$objInstance; 
    
    } # end method 
	
    /* 
     * Passes on any static calls to this class onto the singleton PDO instance 
     * @param $chrMethod, $arrArguments 
     * @return $mix 
     */ 
    final public static function __callStatic( $chrMethod, $arrArguments ) { 
            
        $objInstance = self::getInstance(); 
        
        return call_user_func_array(array($objInstance, $chrMethod), $arrArguments); 
        
    } # end method
}


?>